package com.aplink.generic.pojo.controlspec;

import java.io.Serializable;

import android.text.TextUtils;
import android.view.View.OnClickListener;

import com.aplink.generic.constant.type.ActionType;
import com.aplink.generic.constant.type.ControlStatus;
import com.aplink.generic.constant.type.ControlType;
import com.aplink.generic.interfaces.OnGetObjProInfo;
import com.aplink.generic.pojo.ValueList;
import com.aplink.generic.pojo.formdesign.ContextMenu;
import com.aplink.generic.util.ResourcesHelper;
import com.aplink.generic.util.objectrule.EnableCondition;
import com.aplink.generic.util.objectrule.ObjectBaseRule;

public abstract class ControlSpec implements Serializable {
	private static final long serialVersionUID = 1053726189505044376L;
	private boolean isLoadByConfig;
	private boolean isToggleAutoSync;
	private boolean isToggleOfflineMode;
	private boolean isVisibility;
	private ActionType mActionType;
	private String mAnimation;
	private ContextMenu mContextMenu;
	private String mControlId;
	private ControlStatus mControlStatus;
	private ControlType mControlType;
	private String mDataObject;
	private EnableCondition mEnableCondition;
	private String mFilterBy;
	private OnGetObjProInfo mGetObjProInfo;
	private String mMappingName;
	private ObjectBaseRule mObjectBaseRule;
	private OnClickListener mOnClickListener;
	private String mRefreshControl;
	private String mRefreshValue;
	private String mValidationGroup;
	private String mValue;
	private ValueList mValueList;

	public ControlSpec() {
		setContextMenus(new ContextMenu());
	}

	public ActionType getActionType() {
		return this.mActionType;
	}

	public String getAnimation() {
		return this.mAnimation;
	}

	public int getAnimationID() {
		if (TextUtils.isEmpty(this.mAnimation)) {
			return ResourcesHelper.RESOURCE_NOT_FOUND;
		}
		return ResourcesHelper.getAnimationIdByName(this.mAnimation);
	}

	public ContextMenu getContextMenus() {
		return mContextMenu;
	}

	public ControlStatus getControlStatus() {
		return mControlStatus;
	}

	/**
	 * The type of this control.<br/>
	 * This property mapping for "ctltype" attribute.<br/>
	 * Example: ctltype="EditText"
	 * 
	 * @return
	 */
	public ControlType getControlType() {
		return this.mControlType;
	}

	/**
	 * Data table name.<br/>
	 * This property mapping for "dataobj" attribute.<br/>
	 * Example: dataobj="ShopTable"
	 * 
	 * @param mDataObject
	 */
	public String getDataObject() {
		return this.mDataObject;
	}

	public EnableCondition getEnableCondition() {
		return this.mEnableCondition;
	}

	public String getFilterBy() {
		return this.mFilterBy;
	}

	public String getFullColumnName() {
		return this.mDataObject + "." + this.mMappingName;
	}

	public OnGetObjProInfo getGetObjProInfo() {
		return this.mGetObjProInfo;
	}

	/**
	 * The ID by String of control.<br/>
	 * This property mapping for "id" attribute.<br/>
	 * Example: id="txt_shop_name"
	 * 
	 * @return ControlId by String
	 */
	public String getIDName() {
		return this.mControlId;
	}

	public int getIDValue() {
		if (TextUtils.isEmpty(mControlId)) {
			return ResourcesHelper.RESOURCE_NOT_FOUND;
		}
		return ResourcesHelper.getViewIdByName(mControlId);
	}

	/**
	 * The table column name.<br/>
	 * This property mapping for "mappingname" attribute.<br/>
	 * Example: mappingname="ShopName"
	 * 
	 * @return MappingName
	 */
	public String getMappingName() {
		return this.mMappingName;
	}

	public ObjectBaseRule getObjectBaseRule() {
		return this.mObjectBaseRule;
	}

	public OnClickListener getOnClickListener() {
		return this.mOnClickListener;
	}

	public String getRefreshControl() {
		return this.mRefreshControl;
	}

	public String getRefreshValue() {
		return this.mRefreshValue;
	}

	/**
	 * The String value to validate group of control.<br/>
	 * This property mapping for "validationgroup" element.<br/>
	 * Example: <validationgroup>Submit</validationgroup>
	 * 
	 * @return
	 */
	public String getValidationGroup() {
		return this.mValidationGroup;
	}

	/**
	 * the value of control. <br/>
	 * With button, this value use for button text.<br/>
	 * Example: value="Submit"
	 * 
	 * @return
	 */
	public String getValue() {
		return this.mValue;
	}

	public ValueList getValueList() {
		return this.mValueList;
	}

	public boolean hasBaseRule() {
		return this.mObjectBaseRule != null;
	}

	public boolean isLoadByConfig() {
		return this.isLoadByConfig;
	}

	public boolean isToggleAutoSync() {
		return this.isToggleAutoSync;
	}

	public boolean isToggleOfflineMode() {
		return this.isToggleOfflineMode;
	}

	/**
	 * The rule to allow the visibility of control.<br/>
	 * This property mapping for "visibility" attribute.<br/>
	 * Example: visibility="N"
	 * 
	 * @return
	 */
	public boolean isVisibility() {
		return this.isVisibility;
	}

	public void setActionType(final ActionType actionType) {
		this.mActionType = actionType;
	}

	public void setAnimation(final String animation) {
		this.mAnimation = animation;
	}

	public void setContextMenus(ContextMenu contextMenu) {
		mContextMenu = contextMenu;
	}

	/**
	 * The ID by String of control.<br/>
	 * This property mapping for "id" attribute.<br/>
	 * Example: id="txt_shop_name"
	 * 
	 * @param controlId
	 */
	public void setControlId(final String controlId) {
		this.mControlId = controlId;
	}

	public void setControlStatus(ControlStatus controlStatus) {
		mControlStatus = controlStatus;
	}

	/**
	 * The type of this control.<br/>
	 * This property mapping for "ctltype" attribute.<br/>
	 * Example: ctltype="EditText"
	 * 
	 * @param controlType
	 */
	public void setControlType(final ControlType controlType) {
		this.mControlType = controlType;
	}

	/**
	 * The type of this control.<br/>
	 * This property mapping for "ctltype" attribute.<br/>
	 * Example: ctltype="EditText"
	 * 
	 * @param controlType
	 */
	public void setControlType(final String controlType) {
		this.mControlType = ControlType.get(controlType);
	}

	/**
	 * Data table name.<br/>
	 * This property mapping for "dataobj" attribute.<br/>
	 * Example: dataobj="ShopTable"
	 * 
	 * @param dataObject
	 */
	public void setDataObject(final String dataObject) {
		this.mDataObject = dataObject;
	}

	public void setEnableCondition(final EnableCondition enableCondition) {
		this.mEnableCondition = enableCondition;
	}

	public void setFilterBy(final String selectWhere) {
		this.mFilterBy = selectWhere;
	}

	public void setLoadByConfig(final boolean isLoadByConfig) {
		this.isLoadByConfig = isLoadByConfig;
	}

	/**
	 * The property or the table column name.<br/>
	 * This property mapping for "mappingname" attribute.<br/>
	 * Example: mappingname="ShopName"
	 * 
	 * @param mappingName
	 */
	public void setMappingName(final String mappingName) {
		this.mMappingName = mappingName;
	}

	public void setObjectBaseRule(final ObjectBaseRule objectBaseRule) {
		this.mObjectBaseRule = objectBaseRule;
	}

	public void setOnClickListener(final OnClickListener onClickListener) {
		this.mOnClickListener = onClickListener;
	}

	public void setOnGetObjProInfo(final OnGetObjProInfo getObjProInfo) {
		this.mGetObjProInfo = getObjProInfo;
	}

	public void setRefreshControl(final String refreshControl) {
		this.mRefreshControl = refreshControl;
	}

	public void setRefreshValue(final String refreshValue) {
		this.mRefreshValue = refreshValue;
	}

	public void setToggleAutoSync(final boolean isToggleAutoSync) {
		this.isToggleAutoSync = isToggleAutoSync;
	}

	public void setToggleOfflineMode(final boolean isToggleOfflineMode) {
		this.isToggleOfflineMode = isToggleOfflineMode;
	}

	/**
	 * The String value to validate group of control.<br/>
	 * This property mapping for "validationgroup" element.<br/>
	 * Example: <validationgroup>Submit</validationgroup>
	 * 
	 * @param validationGroup
	 */
	public void setValidationGroup(final String validationGroup) {
		this.mValidationGroup = validationGroup;
	}

	/**
	 * the value of control. <br/>
	 * With button, this value use for button text.<br/>
	 * Example: value="Submit"
	 * 
	 * @param text
	 */
	public void setValue(final String text) {
		this.mValue = text;
	}

	public void setValueList(final ValueList valueList) {
		this.mValueList = valueList;
	}

	/**
	 * The rule to allow the visibility of control.<br/>
	 * This property mapping for "visibility" attribute.<br/>
	 * Example: visibility="N"
	 * 
	 * @param visibility
	 */
	public void setVisibility(final boolean visibility) {
		this.isVisibility = visibility;
	}
}
